package com.ymatou.iapi.dguser.testcase;

import com.ymatou.iapi.dguser.parameter.UpdateUserWxinfoBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.UpdateUserWxinfoCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.database.model.DGUserInfo;
import com.ymttest.database.sqlwapper.DGUserWapper;

import java.util.List;
import java.util.Map;

import org.junit.*;
import org.junit.experimental.categories.Category;
/**
*更新用户微信信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UpdateUserWxinfo{
	private static UpdateUserWxinfoBean updateuserwxinfoBean;
	private static UpdateUserWxinfoCall updateuserwxinfoCall;
	DGUserWapper DGUserWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新用户微信信息");
	}

	@Before
	public void caseUp() {
		updateuserwxinfoBean=new UpdateUserWxinfoBean();
		updateuserwxinfoCall=new UpdateUserWxinfoCall();
		DGUserWapper=new DGUserWapper();

	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updateuserwxinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private void verifyDB(UpdateUserWxinfoBean updateUserWxinfoBean) {
		DGUserInfo dgUserInfo = DGUserWapper.selectDGUserInfo(updateUserWxinfoBean.getUserId()).get(0);
		Logger.verifyEquals(updateUserWxinfoBean.getNickname(),dgUserInfo.getNickname(),"验证nickName");
		Logger.verifyEquals(updateUserWxinfoBean.getGender(),dgUserInfo.getUserGender(),"验证gender");
		if(updateUserWxinfoBean.getLogoUrl()!=null&&updateUserWxinfoBean.getLogoUrl().length()>0) {
			Logger.verifyEquals(updateUserWxinfoBean.getLogoUrl(),dgUserInfo.getLogoUrl(),"验证LogoUrl");
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserWxinfo_001() {
		Logger.start(true,"更新用户微信信息");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			Integer user = DGUserCallService.UserCreateCall(u);
			updateuserwxinfoBean.setGender(2);
			updateuserwxinfoBean.setLogoUrl("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701.jpg");
			updateuserwxinfoBean.setUserId(user);
			updateuserwxinfoBean.setNickname("nihao");
			updateuserwxinfoCall.setData(updateuserwxinfoBean);
			updateuserwxinfoCall.callService();
			Logger.verifyEquals("true", updateuserwxinfoCall.getString("success"), "验证success");
			verifyDB(updateuserwxinfoBean);
			MessageListBean MessageListBean = MqQueryCallService.initGodUpdateWxUserInfo(user);
			 List<Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			joa.forEach(ele->{
				Logger.debug(ele.toString());
			});
			Logger.verifyEquals(true, joa.size()>0, "验证发送总线记录");
			Logger.verifyEquals(user.toString(),  joa.get(0).get("userId").toString(), "验证发送消息");
		} catch (Exception e) {
			Logger.fail(e);
		}catch (Throwable throwable) {
			throwable.printStackTrace();
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateUserWxinfo_002() {
		Logger.start(true,"更新用户微信信息,不输入头像成功JIRACONN-30513");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			updateuserwxinfoBean.setGender(2);
//			updateuserwxinfoBean.setLogoUrl("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701.jpg");
			updateuserwxinfoBean.setUserId(user);
			updateuserwxinfoBean.setNickname("nihao");
			updateuserwxinfoCall.setData(updateuserwxinfoBean);
			updateuserwxinfoCall.callService();
			Logger.verifyEquals("true", updateuserwxinfoCall.getString("success"), "验证success");
			verifyDB(updateuserwxinfoBean);
		} catch (Exception e) {
			Logger.fail(e);
		}catch (Throwable throwable) {
			throwable.printStackTrace();
		}
	}
}